Home:ALL Converter>What is the equivalent of GetEncoding("28591") of C# in Python?

What is the equivalent of GetEncoding("28591") of C# in Python?

Ask Time:2018-09-30T20:14:09         Author:Danial Sa'adati

Json Formatter

I want to get the code of a device from COM6, I easily get the output from C# using the code below:

serialPort1.Encoding = System.Text.Encoding.GetEncoding(28591);

but I don't know how to do it in Python.

I already tried:

import serial
import time
ser = serial.Serial()
ser.port='COM6'
ser.baudrate=9600
ser.parity=serial.PARITY_NONE
ser.stopbits=serial.STOPBITS_ONE
ser.bytesize=serial.EIGHTBITS
ser.timeout=2

if ser.is_open:
    ser.close()
else:
    ser.open()
print("connected to: " + ser.portstr)


while True:
    ser.flushInput()
    time.sleep(0.01)
    data_raw = (ser.readline())
    print(data_raw.decode("utf-8"))

Author:Danial Sa'adati,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52577772/what-is-the-equivalent-of-getencoding28591-of-c-sharp-in-python
yy